import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { TypeOrmModule } from "@nestjs/typeorm";
import { ScheduleModule } from "@nestjs/schedule"; // 添加定时任务模块
import { AppController } from "./app.controller";
import { UserController } from "./controllers/user.controller";
import { AreaController } from "./controllers/area.controller";
import { RechargeController } from "./controllers/recharge.controller";
import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";
import { AuthGuard } from "./auth/auth.guard";
import { UserService } from "./services/user.service";
import { UserEntity } from "./entities/user.entity";
import { AreaEntity } from "./entities/area.entity";
import { CharacterEntity } from "./entities/character.entity";
import { CharacterAttributeEntity } from "./entities/character-attribute.entity";
import { CharacterDetailedAttributeEntity } from "./entities/character-detailed-attribute.entity";
import { CharacterSkillEntity } from "./entities/character-skill.entity";
import { SocialRelationEntity } from "./entities/social-relation.entity";
import { CharacterReligionEntity } from "./entities/character-religion.entity";
import { CharacterResidenceEntity } from "./entities/character-residence.entity";
import { CharacterStoneEntity } from "./entities/character-stone.entity";
import { CharacterResourcesEntity } from "./entities/character-resources.entity";
import { CharacterInventoryEntity } from "./entities/character-inventory.entity";
import { CharacterMineralEntity } from "./entities/character-mineral.entity";
import { ChatMessageEntity } from "./entities/chat-message.entity";
import { PrivateMessageEntity } from "./entities/private-message.entity";
import { AnnouncementEntity } from "./entities/announcement.entity";
import { ItemEntity } from "./entities/item.entity";
import { BasicItemEntity } from "./entities/basic-item.entity";
import { MonthlyCardEntity } from "./entities/monthly-card.entity";
import { SystemMessageEntity } from "./entities/system-message.entity";
import { MapAreaEntity } from "./entities/map-area.entity";
import { CharacterLocationEntity } from "./entities/character-location.entity";
import { DeputyGeneral } from "./entities/deputy-general.entity";
import { DeputyGeneralBase } from "./entities/deputy-general-base.entity";
import { PlayerDeputy } from "./entities/player-deputy.entity";
import { DeputyGeneralSkillLearned } from "./entities/deputy-general-skill-learned.entity";
import { DeputyGeneralEquipment } from "./entities/deputy-general-equipment.entity";
import { DeputyGeneralStone } from "./entities/deputy-general-stone.entity";
import { PlayerDeputyWarehouse } from "./entities/player-deputy-warehouse.entity";
import { SkillBase } from "./entities/skill-base.entity";
import { LevelExperienceEntity } from "./entities/level-experience.entity";
import { EquipmentBaseEntity } from "./entities/equipment-base.entity";
import { FactionEntity } from "./entities/faction.entity";
import { FactionMemberEntity } from "./entities/faction-member.entity";
import { CharacterMedicineEntity } from "./entities/character-medicine.entity";
import { CharacterEquipmentInventoryEntity } from "./entities/character-equipment-inventory.entity";
import { NpcClusterEntity } from "./entities/npc-cluster.entity";
import { NpcDetailEntity } from "./entities/npc-detail.entity";
import { MountBaseEntity } from "./entities/mount-base.entity";
import { CharacterMountEntity } from "./entities/character-mount.entity";
import { GemBaseEntity } from "./entities/gem-base.entity";
import { GemAttributeEntity } from "./entities/gem-attribute.entity";
import { CharacterGemInventoryEntity } from "./entities/character-gem-inventory.entity";
import { EquipmentGemSocketEntity } from "./entities/equipment-gem-socket.entity";
import { GemMiningEntity } from "./entities/gem-mining.entity";
import { MountTrainingEntity } from "./entities/mount-training.entity";
import { AreaService } from "./services/area.service";
import { CharacterService } from "./services/character.service";
import { ChatMessageService } from "./services/chat-message.service";
import { SystemMessageService } from "./services/system-message.service";
import { PrivateMessageService } from "./services/private-message.service";
import { AnnouncementService } from "./services/announcement.service";
import { ItemService } from "./services/item.service";
import { BasicItemService } from "./services/basic-item.service";
import { InventoryService } from "./services/inventory.service";
import { MonthlyCardService } from "./services/monthly-card.service";
import { CharacterSkillService } from "./services/character-skill.service";
import { ShopService } from "./services/shop.service";
import { DatabaseInitService } from "./services/database-init.service";
import { DatabaseSyncService } from "./services/database-sync.service";
import { databaseConfig } from "./config/database.config";
import { DeputyGeneralService } from "./services/deputy-general.service";
import { FactionService } from "./services/faction.service";
import { CharacterMedicineService } from "./services/character-medicine.service";
import { CharacterEquipmentInventoryService } from "./services/character-equipment-inventory.service";
import { EquipmentBaseService } from "./services/equipment-base.service";
import { EquipmentWsHandlers } from "./gateway/equipment-ws-handlers";
import { MountWsHandlers } from "./gateway/mount-ws-handlers";
import { NpcService } from "./services/npc.service";
import { BankService } from "./services/bank.service";
import { MountBaseService } from "./services/mount-base.service";
import { CharacterMountService } from "./services/character-mount.service";
import { GemService } from "./services/gem.service";
import { AppWsGateway } from "./gateway/ws.gateway";
import { RedisModule } from "./modules/redis.module";
import { RedisTestController } from "./controllers/redis-test.controller";
import { CharacterController } from "./controllers/character.controller";
import { ChatMessageController } from "./controllers/chat-message.controller";
import { AnnouncementController } from "./controllers/announcement.controller";
import { CasinoModule } from "./modules/casino/casino.module"; // 导入完整的娱乐城模块
import { SchedulerModule } from "./modules/scheduler/scheduler.module"; // 导入定时任务模块
import { MapAreaModule } from "./modules/map-area/map-area.module"; // 导入地图区域模块
import { CharacterLocationModule } from "./modules/character-location/character-location.module"; // 导入玩家位置模块
import { UserAuthModule } from "./modules/user-auth.module"; // 导入用户认证模块
import { DeputyGeneralModule } from "./modules/deputy-general/deputy-general.module"; // 导入副将系统模块
import { LevelExperienceModule } from "./modules/level-experience/level-experience.module"; // 导入等级经验模块
import { MountLevelExperienceEntity } from "./entities/mount-level-experience.entity"; // 导入坐骑等级经验实体
import { MountLevelExperienceService } from "./services/mount-level-experience.service"; // 导入坐骑等级经验服务
import {
  TalentStoneEntity,
  TalentStoneLevelEntity,
  TalentStoneBaseEntity,
} from "./entities/talent-stone.entity"; // 导入天赋石实体
import { TalentStoneService } from "./services/talent-stone.service"; // 导入天赋石服务
import { TalentStoneWsHandlers } from "./gateway/talent-stone-ws-handlers"; // 导入天赋石WebSocket处理器
import { CharacterTrainingEntity } from "./entities/character-training.entity"; // 导入角色训练实体
import { CharacterTrainingService } from "./services/character-training.service"; // 导入角色训练服务
import { CharacterTrainingSchedulerService } from "./services/character-training-scheduler.service"; // 导入角色训练定时任务服务
import { CharacterTrainingWsHandlers } from "./gateway/character-training-ws-handlers"; // 导入角色训练WebSocket处理器
import { HouseTrainingTaskEntity } from "./entities/house-training-task.entity";
import { CharacterHealClaimEntity } from "./entities/character-heal-claim.entity";
import { HouseTrainingService } from "./services/house-training.service";
import { HouseTrainingSchedulerService } from "./services/house-training-scheduler.service";
import { CharacterAttributePointsEntity } from "./entities/character-attribute-points.entity"; // 导入角色属性点实体
import { CharacterEquipmentEntity } from "./entities/character-equipment.entity";
import { PlayerOnlineTimeEntity } from "./entities/player-online-time.entity"; // 导入角色装备实体
import { CharacterAttributeService } from "./services/character-attribute.service"; // 导入角色属性服务
import { CharacterEquipmentService } from "./services/character-equipment.service"; // 导入角色装备服务
import { PlayerOnlineTimeService } from "./services/player-online-time.service"; // 导入玩家在线时长服务
import { TimestampService } from "./services/timestamp.service"; // 导入时间戳服务
import { TimestampInterceptor } from "./interceptors/timestamp.interceptor"; // 导入时间戳拦截器
import { ManualTimestampService } from "./services/manual-timestamp.service"; // 导入手动时间戳服务
import { DeputyAttributeService } from "./services/deputy-attribute.service"; // 导入副将属性服务
import { DeputyAttributePointsEntity } from "./entities/deputy-attribute-points.entity"; // 导入副将属性点实体
import { VipStatusEntity } from "./entities/vip-status.entity";
import { VipService } from "./services/vip.service";
import { VipRewardConfigEntity } from "./entities/vip-reward-config.entity";
import { CharacterSinewClaimEntity } from "./entities/character-sinew-claim.entity";
import { CharacterSinewWindowClaimEntity } from "./entities/character-sinew-window-claim.entity";
import { TombPitEntity } from "./entities/tomb-pit.entity";
import { TombDailyCounterEntity } from "./entities/tomb-daily-counter.entity";
import { TombDigLogEntity } from "./entities/tomb-dig-log.entity";
import { TombService } from "./services/tomb.service";
import { TombWsHandlers } from "./gateway/tomb-ws-handlers";
import { PlayerStatusService } from "./services/player-status.service";
import { StallEntity } from "./entities/stall.entity";
import { StallItemEntity } from "./entities/stall-item.entity";
import { StallTradeEntity } from "./entities/stall-trade.entity";
import { StallService } from "./services/stall.service";
import { SkillUpgradeThresholdEntity } from "./entities/skill-upgrade-threshold.entity";
import { GoldTradeOrderEntity } from "./entities/gold-trade-order.entity";
import { GoldTradeService } from "./services/gold-trade.service";

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    ScheduleModule.forRoot(), // 添加全局定时任务模块配置
    TypeOrmModule.forRoot(databaseConfig),
    TypeOrmModule.forFeature([
      UserEntity,
      AreaEntity,
      CharacterEntity,
      CharacterAttributeEntity,
      CharacterDetailedAttributeEntity,
      CharacterSkillEntity,
      SocialRelationEntity,
      CharacterReligionEntity,
      CharacterResidenceEntity,
      CharacterStoneEntity,
      CharacterResourcesEntity,
      CharacterInventoryEntity,
      CharacterMineralEntity,
      ChatMessageEntity,
      PrivateMessageEntity,
      AnnouncementEntity,
      ItemEntity,
      BasicItemEntity,
      MonthlyCardEntity,
      SystemMessageEntity,
      MapAreaEntity,
      CharacterLocationEntity,
      DeputyGeneral,
      DeputyGeneralBase,
      PlayerDeputy,
      DeputyGeneralSkillLearned,
      DeputyGeneralEquipment,
      DeputyGeneralStone,
      PlayerDeputyWarehouse,
      SkillBase,
      LevelExperienceEntity,
      EquipmentBaseEntity,
      FactionEntity,
      FactionMemberEntity,
      CharacterMedicineEntity,
      CharacterEquipmentInventoryEntity,
      NpcClusterEntity,
      NpcDetailEntity,
      MountBaseEntity,
      CharacterMountEntity,
      MountTrainingEntity,
      GemBaseEntity,
      GemAttributeEntity,
      CharacterGemInventoryEntity,
      EquipmentGemSocketEntity,
      GemMiningEntity,
      MountLevelExperienceEntity,
      SkillUpgradeThresholdEntity,
      TalentStoneEntity,
      TalentStoneLevelEntity,
      TalentStoneBaseEntity,
      CharacterTrainingEntity,
      HouseTrainingTaskEntity,
      CharacterAttributePointsEntity,
      CharacterEquipmentEntity,
      DeputyAttributePointsEntity,
      VipStatusEntity,
      VipRewardConfigEntity,
      CharacterSinewClaimEntity,
      CharacterSinewWindowClaimEntity,
      TombPitEntity,
      TombDailyCounterEntity,
      TombDigLogEntity,
      CharacterHealClaimEntity,
      // market stall
      StallEntity,
      StallItemEntity,
      StallTradeEntity,
      GoldTradeOrderEntity,
    ]),
    RedisModule,
    UserAuthModule, // 导入用户认证模块
    CasinoModule, // 使用完整的娱乐城模块
    SchedulerModule, // 使用定时任务模块
    MapAreaModule, // 使用地图区域模块
    CharacterLocationModule, // 使用玩家位置模块
    DeputyGeneralModule, // 使用副将系统模块
    LevelExperienceModule, // 使用等级经验模块
    TypeOrmModule.forFeature([PlayerOnlineTimeEntity]), // 注册玩家在线时长实体仓库
  ],
  controllers: [
    AppController,
    UserController,
    AreaController,
    RechargeController,
    RedisTestController,
    CharacterController,
    ChatMessageController,
    AnnouncementController,
  ],
  providers: [
    UserService,
    AreaService,
    CharacterService,
    ChatMessageService,
    SystemMessageService,
    PrivateMessageService,
    AnnouncementService,
    ItemService,
    BasicItemService,
    InventoryService,
    MonthlyCardService,
    CharacterSkillService,
    ShopService,
    DatabaseInitService,
    DatabaseSyncService,
    FactionService,
    CharacterMedicineService,
    CharacterEquipmentInventoryService,
    EquipmentBaseService,
    EquipmentWsHandlers,
    MountWsHandlers,
    TalentStoneWsHandlers,
    CharacterTrainingService,
    HouseTrainingService,
    HouseTrainingSchedulerService,
    CharacterTrainingSchedulerService,
    CharacterTrainingWsHandlers,
    NpcService,
    BankService,
    MountBaseService,
    CharacterMountService,
    MountLevelExperienceService,
    TalentStoneService,
    GemService,
    CharacterAttributeService,
    CharacterEquipmentService,
    DeputyAttributeService,
    VipService,
    PlayerOnlineTimeService,
    TimestampService,
    TombService,
    PlayerStatusService,
    StallService,
    GoldTradeService,
    ManualTimestampService,
    AppWsGateway,
    TombWsHandlers,
    { provide: APP_GUARD, useClass: AuthGuard },
    { provide: APP_INTERCEPTOR, useClass: TimestampInterceptor },
  ],
})
export class AppModule {}
